package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.query.album.AlbumInfoQuery;
import com.atguigu.tingshu.vo.album.AlbumInfoVo;
import com.atguigu.tingshu.vo.album.AlbumListVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "专辑管理")
@RestController
@RequestMapping("api/album")
@SuppressWarnings({"all"})
public class AlbumInfoApiController {

	@Autowired
	private AlbumInfoService albumInfoService;

	@Operation(summary = "新增专辑")
	@PostMapping(value = "/albumInfo/saveAlbumInfo")
	public Result saveAlbumInfo(@RequestBody AlbumInfoVo albumInfoVo) {
		albumInfoService.saveAlbumInfo(albumInfoVo);
		return Result.ok();
	}

	@Operation(summary = "查看当前用户专辑分页列表")
	@PostMapping(value = "/albumInfo/findUserAlbumPage/{pageNo}/{pageSize}")
	public Result<Page<AlbumListVo>> findUserAlbumPage(@PathVariable("pageNo") Integer pageNo,
													   @PathVariable("pageSize") Integer pageSize,
													   @RequestBody AlbumInfoQuery albumInfoQuery) {
		Page<AlbumListVo> page = albumInfoService.findUserAlbumPage(pageNo, pageSize, albumInfoQuery);
		return Result.ok(page);
	}

	@Operation(summary = "删除专辑")
	@DeleteMapping(value = "/albumInfo/removeAlbumInfo/{id}")
	public Result removeAlbumInfo(@PathVariable("id") Long id) {
		albumInfoService.removeAlbumInfo(id);
		return Result.ok();
	}

	@Operation(summary = "根据Id查询专辑信息")
	@GetMapping(value = "/albumInfo/getAlbumInfo/{id}")
	public Result<AlbumInfo> getAlbumInfoById(@PathVariable("id") Long id) {
		AlbumInfo albumInfo = albumInfoService.getAlbumInfoById(id);
		return Result.ok(albumInfo);
	}

	@Operation(summary = "修改专辑")
	@PutMapping(value = "/albumInfo/updateAlbumInfo/{id}")
	public Result updateAlbumInfoById(@PathVariable("id") Long id, @RequestBody AlbumInfo albumInfo) {
		albumInfoService.updateAlbumInfo(id, albumInfo);
		return Result.ok();
	}

}

